// pages/stvideoList/stvideoList.js
import resource from '../../libs/resource.js'

Page({
  data: {
    loading:true,
    scrollListToTop: false,
    statusBarHeight: 0,
    logo_image: resource.stvideo_logo_image,
    head_image: resource.stvideo_head_image,
    videos: []
  },
  onLoad: function (options) {
    var onling = getApp().globalData.onling
    if (!onling) {
      this.get_videos()
      wx.setNavigationBarTitle({
        title: '短视频'
      })
    }
    var _this = this
    var app = getApp();
    wx.getSystemInfo({
      success: function (res) {
        console.log(res)
        _this.setData({
          statusBarHeight: res.statusBarHeight
        })
        app.globalData.statusBarHeight = res.statusBarHeight
      }
    })
    console.log(app.globalData.statusBarHeight)
  },
  onShareAppMessage() {

  },
  //获取视频资源
  get_videos() {
    var _this = this
    wx.cloud.callFunction({
      name: 'video-json',
      data: {
        action: 'getVideoData'
      },
      success: function (res) {
        console.log(res)
        _this.setData({
          loading:false,
          videos: res.result
        })
      },
      fail: console.error
    })
  },
  //滚动监听
  onPageScroll: function (e) {
    // console.log(e.scrollTop) //这个就是滚动到的位置,可以用这个位置来写判断
    // var scrollToTop = false;
    // if (e.scrollTop > 180) {
    //   scrollToTop = true;
    // } else {
    //   scrollToTop = false;
    // }
    // this.setData({
    //   scrollListToTop: scrollToTop
    // })
  },
  //类型点击
  mainTypeClick(event) {
    var name = event.currentTarget.dataset.name
    var key = event.currentTarget.dataset.key
    // console.log(event)
    console.log(name, key)
    wx.navigateTo({
      url: "stvideo/stvideo?title=" + name +
        "&key=" + key
    })
  },
  //类型item点击
  mainTypeItemClick(event) {
    var name = event.currentTarget.dataset.name
    var key = event.currentTarget.dataset.key
    console.log(event)
    console.log(name, key)
    wx.navigateTo({
      url: "stvideo/stvideo?title=" + name +
        "&key=" + key
    })
  },
  //返回按钮监听
  backListener(event) {
    wx.navigateBack({

    })
  }
})